const logger = require("./logger");

// 仅限 Windows 系统
const spawn = require('child_process').spawn;
const iconv = require('iconv-lite');

let log = logger.getLogger('jzt');

module.exports.exec = function (batFile) {
    // test.bat
    log.info('Start running bat: ' + batFile);
    let cmd = spawn(batFile);

    cmd.stdout.on('data', (data) => {
        var str = iconv.decode(data, 'GBK');
        log.info(`stdout: ${str}`);
    });

    cmd.stderr.on('data', (data) => {
        var str = iconv.decode(data, 'GBK');
        log.info(`stderr: ${str}`);
    });

    cmd.on('close', (code) => {
        log.info('End running bat: ' + batFile + ', 退出码: ' + code);
    });
};